package hrm.daoimple;

import hrm.dao.PagingDAO;
import hrm.ibatis.SqlDaoSuport;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

public class PagingDAOImple   extends SqlDaoSuport implements PagingDAO{
	
	private static Logger log = Logger.getLogger(LoginDAOImple.class);

	public int getCount(String searchType[], String searchValue[], String queryId, boolean isT) {
		Map<String, Object> params = new HashMap<String, Object>();
		
		if(searchType!=null){
			for(int i=0;i<searchType.length;++i){
				if(searchValue[i]!=null && searchValue[i].length()>0){
					if(isT){
						params.put(searchType[i], "%"+searchValue[i]+"%");
					}else{
						params.put(searchType[i], searchValue[i]);
					}
				}
			}
		}
		
		int count = 0;
		try {
			count = ((Integer)this.getSqlMapper().queryForObject(queryId, params)).intValue();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return count;
	}

	public List getList(String searchType[], String searchValue[], int pageSize,
			int curPage, String queryId, boolean isT) {
	
		Map<String, Object> params = new HashMap<String, Object>();
		
		if(searchType!=null){
			for(int i=0;i<searchType.length;++i){
				if(searchValue[i]!=null && searchValue[i].length()>0){
					if(isT){
						params.put(searchType[i], "%"+searchValue[i]+"%");
					}else{
						params.put(searchType[i], searchValue[i]);
					}
				}
			}
		}
		params.put("pageSize", new Integer(pageSize));
		params.put("curPage", new Integer(curPage));
		
		List lists = null;
		try {
			lists = this.getSqlMapper().queryForList(queryId, params);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return lists;
	}
}
